﻿using System;
using System.Threading.Tasks;

namespace Task异常
{
    class Program
    {
        static void Main(string[] args)
        {
            var task0 = Task.Factory.StartNew(() => {
                var task1 = Task.Factory.StartNew(() => {
                    throw new Exception("我是task1异常");
                },TaskCreationOptions.AttachedToParent);
                var task2 = Task.Factory.StartNew(() => {
                    throw new Exception("我是task2异常");
                }, TaskCreationOptions.AttachedToParent);
            });

            try
            {
                task0.Wait();
            }
            catch (AggregateException ex)
            {
                //foreach (var item in ex.InnerExceptions)
                //{
                //    Console.WriteLine($"msg={item.Message},type={item.GetType().Name}");
                //}
                ex.Handle((x) =>
                {
                    // 如果是我指定的某个异常  不在抛， 就返回true否则，就返回false 让他继续往上抛
                    //if (x is Exception)
                    {
                        return true;
                    }
                    return false;
                });
            }



            Console.Read();
        }
    }
}
